/*******************************************************************************
DialogKit.h

	Author:		LiuDingXi
	e-mail:		liudx@gmail.com
	Date time:	2009-08-07

	Copyright (C) 2009
	All rights reserved.
	
*******************************************************************************/

#ifndef _DIALOGKIT_H_
#define _DIALOGKIT_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "BaseParser.h"
#include "SpriteKit.h"
#include "Coder.h"

class CDialogKit : public CBaseParser
{
public:
	CDialogKit();
	virtual ~CDialogKit();


public:
	BOOL	Load(CArchive& ar);
	BOOL	Store(CArchive& ar);

	BOOL	Free();

	BOOL	SaveTo(LPCTSTR szPathFile);

public:

	struct SKIT : public CSpriteKit
	{
		CString szName;
		CString szFile;
		BOOL bExpand;
	};
	list<SKIT*> m_SprKits;

	typedef CSpriteKit::SPRITE SPRITE;

	enum {tSprite, tCtrl};

	struct CONTROL;

	struct CITEM
	{
		CString szName;
		int nPosX;
		int nPosY;
		UINT nType;
		union
		{
			SPRITE*	pSprite;
			CONTROL* pControl;
		};

		void OnDraw(CDC* pDC, int x, int y);
		void OnUpdate();
		bool HitTest(int x, int y);
		void GetRect(RECT& rect)const;
	};

	struct CONTROL
	{
		CString szType;
		CString szName;
		list<CITEM*>	ItemList;

		void OnDraw(CDC* pDC, int x, int y);
		void OnUpdate();

		void GetRect(RECT& rect)const;

		bool HitTest(int x, int y);

		SceneDat::PTR ptr;

		UINT GetType()const;
	};

	list<CONTROL*>	m_Controls;


	enum {tItem, tDialog};

	struct TDATA
	{
		UINT nType;
		CString szName; 
	};

	enum NTFID
	{
		NTF_NONE,
		NTF_CLOSE,
		NTF_CANCEL,
		NTF_OK,
	};

	struct DITEM : public TDATA
	{
		DITEM(){nType=tItem;}

		int			nPosX;
		int			nPosY;
		int			nNtfy;

		CONTROL*	pCtrl;
		CString		szScript;

		void GetRect(RECT& rect)const;

		SceneDat::INT	idx;
	};

	struct DIALOG : public TDATA
	{
		DIALOG(){nType=tDialog;}
		
		list<DITEM*> ItemList;

		DITEM* AddItem(LPCTSTR p);

		SceneDat::PTR ptr;
		SceneDat::INT idx;

		BOOL Build(LPCTSTR szOutput);
	};
	
	CONTROL* NewControl(LPCTSTR p);
	DIALOG* NewDialog(LPCTSTR p);

	CITEM* CtrlItemAdd(LPCTSTR p, CONTROL* pControl, UINT nType);

	list<DIALOG*> m_Dialogs;

	BOOL LinkSprite(CITEM* pItem);
	
	BOOL LinkControl(DITEM* pDlgItem);

public:
	DIALOG* FindDialog(LPCTSTR szName);

	void	GetImages(set<SKIT::IMAGE*>& ImgSet);

	int		JoinTo(list<CONTROL*>& refList);
	int		JoinTo(list<DIALOG*>& refList);
};


#endif//_DIALOGKIT_H_
